<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ include file="/taglibs.jsp"%>

<c-rt:set var="midContextPath"
	value='<%=ServerValue.getMidContextPath()%>' />
<c-rt:set var="imgDomain"
	value='<%=ServerValue.getImgDomain()%>' />
<script src="/js/jquery.form.js"></script>
<script language="javascript">

	$().ready(function(){
		//儲存
		$("#saveButton").click(function(){
			if (!validateData()) return false;
			$("#mainForm").attr("action","./savePage.do");
			$("#mainForm").submit();
			return false;
		});

		$("#saveAndPreviewButton").click(function(){
			if (!validateData()) return false;
			$("#mainForm").attr("action","./saveAndPreviewPage.do");
			$("#mainForm").submit();
			return false;
		});

		$("#activityPageTitle").blur(function(){
			var title = $("#activityPageTitle").val();
			if (title != "") {
				var txt = "－耀点100-Yaodian100";
				if (title.indexOf(txt) == -1) {
					title = title + txt;
					$("#activityPageTitle").val(title);
				}
			}
		});
			
		//radio 控制
		var mainVisualImageUrl = $('#mainVisualImageUrl');
		var mainVisualImageTargetUrlOfExistingImage = $('#mainVisualImageTargetUrlOfExistingImage');
		
		var mainVisualImageFile = $('#mainVisualImageFile');
		var mainVisualImageTargetUrlOfUploadImage = $('#mainVisualImageTargetUrlOfUploadImage');
		
		var mainVisualHtmlFilePath = $('#mainVisualHtmlFilePath');
		
		var mainVisualHtmlContent = $('#mainVisualHtmlContent');
		
		//預設
		enableAllPageMasterInput(false);
		mainVisualImageUrl.attr('disabled', false);
		mainVisualImageTargetUrlOfExistingImage.attr('disabled', false);
		
		$('.existingImageFile').click(function() {
			enableAllPageMasterInput(false);
			mainVisualImageUrl.attr('disabled', false);
			mainVisualImageTargetUrlOfExistingImage.attr('disabled', false);
			resetMainVusualInput("1");
		});
		$('.uploadImageFile').click(function() {
			enableAllPageMasterInput(false);
			mainVisualImageFile.attr('disabled', false);
			mainVisualImageTargetUrlOfUploadImage.attr('disabled', false);
			resetMainVusualInput("2");
		});
		$('.htmlFile').click(function() {
			enableAllPageMasterInput(false);
			mainVisualHtmlFilePath.attr('disabled', false);
			resetMainVusualInput("3");
		});
		$('.htmlCode').click(function() {
			enableAllPageMasterInput(false);
			mainVisualHtmlContent.attr('disabled', false);
			resetMainVusualInput("4");
		});

		function enableAllPageMasterInput(switchOn) {
			mainVisualImageUrl.attr('disabled', !switchOn);
			mainVisualImageTargetUrlOfExistingImage.attr('disabled', !switchOn);
			
			mainVisualImageFile.attr('disabled', !switchOn);
			mainVisualImageTargetUrlOfUploadImage.attr('disabled', !switchOn);
			
			mainVisualHtmlFilePath.attr('disabled', !switchOn);
			
			mainVisualHtmlContent.attr('disabled', !switchOn);
		}

		function resetMainVusualInput(contentType) {
			if (contentType != "1") {
				mainVisualImageUrl.val("");
				mainVisualImageTargetUrlOfExistingImage.val("");
			}
			if (contentType != "2") {
				mainVisualImageTargetUrlOfUploadImage.val("");
			}
			if (contentType != "3") {
				mainVisualHtmlFilePath.val("");
			}
			if (contentType != "4") {
				mainVisualHtmlContent.val("");
			}
		}

		var mainVisualContentType = '${activityPage.mainVisualContentType}';
		switch (mainVisualContentType) {
		case '1':
			$('.existingImageFile').click();
			break;
		case '2':
			$('.uploadImageFile').click();
			break;
		case '3':
			$('.htmlFile').click();
			break;
		case '4':
			$('.htmlCode').click();
			break;
		}

		function validateData() {
			if (!validateRequired("activityPage.title","活动页名称")) return false;
			if ($('.existingImageFile').attr("checked")) {
				if (!validateRequired("activityPage.mainVisualImageUrl","图档位置")) return false;
				if (!validateById("mainVisualImageTargetUrlOfExistingImage","点击目的网址",null)) return false;
			}
			if ($('.uploadImageFile').attr("checked")) {
				if ($("#previewImage").val() == null) {
					if (!validateById("mainVisualImageFile",null,"请选择上传图档")) return false;
				}
				if (!validateById("mainVisualImageTargetUrlOfUploadImage","点击目的网址",null)) return false;
			}
			if ($('.htmlFile').attr("checked")) {
				if (!validateRequired("activityPage.mainVisualHtmlFilePath","html档位置")) return false;
			}
			if ($('.htmlCode').attr("checked")) {
				if (!validateRequired("activityPage.mainVisualHtmlContent","自定html代码")) return false;
			}
			return true;
			
		}
		function validateById(id,inputDesc,fullMsg) {
			var obj = $("#"+id);
			if(obj.val() == '') {
				if (inputDesc != null) {
					alert("请输入"+inputDesc);
				} else if (fullMsg != '') {
					alert(fullMsg);
				}
				obj.focus();
				return false;
			}
			return true;
				 
		}
		function validateRequired(name,inputDesc) {
			var obj = $(":input[name='"+name+"']");
			return validateById(obj.attr("id"),inputDesc,null);
		}
		<c:if test="${gotoBlockDetail}">
			location.href = "#blockDetail";
		</c:if>
		
	});

	
	
	
</script>

<s:actionerror />
<s:actionmessage />
<s:fielderror />
	<div class="product">
		<div class="f-link">
			<a href="search.do">回活动页面列表</a>
		</div>
		<br>
		<h1>活动页面管理</h1>
		<div class="stepflow">
			<span class="firstone on"><strong>设置活动主视觉与商品</strong><b>&nbsp;</b>
			</span> 
			<span class="lastone off">
				<s:if test="activityPage.id != null">
					<a href="#" id="saveAndPreviewButton">预览及储存</a>
				</s:if>
				<s:else>预览及储存</s:else>
				<b>&nbsp;</b>
			</span>
		</div>
		<s:form action="page/savePage.do" id="mainForm" method="POST" enctype ="multipart/form-data" >
		<p class="txt-L">
			<strong> <span class="txt-rd">＊</span> 1. 活动页名称： </strong>
			<s:textfield name="activityPage.title" id="activityPageTitle" size="70" maxlength="50"></s:textfield>
			<br> <span class="title-note">（作为网页TITLE与SEO使用。名称命名建议：活动名称。系统会在活动名称后面自动加上<font color="red">－耀点100-Yaodian100</font>）</span>
		</p>
		<p class="txt-L">
			<strong><span class="txt-rd">＊</span> 2. 活动主视觉版块内容：</strong>
		</p>
		<ul class="act-main-img-select">
			<li>
				<s:radio name="activityPage.mainVisualContentType" list="#{'1':''}" cssClass="ipt-radio existingImageFile"></s:radio>
				<span class="title-width-13">图档位置：</span> 
				<s:textfield name="activityPage.mainVisualImageUrl" id="mainVisualImageUrl" maxLength="200" size="70" />
				<br>
				<span class="title-width-13">点击目的网址：</span>
				<s:textfield name="activityPage.mainVisualImageTargetUrl" id="mainVisualImageTargetUrlOfExistingImage" maxLength="200" size="70" />
			</li>
			<li>
				<s:radio name="activityPage.mainVisualContentType" list="#{'2':''}" cssClass="ipt-radio uploadImageFile"></s:radio>
				<span class="title-width-13">上传图档(宽950px)：</span>
				<s:file name="mainVisualImage" id="mainVisualImageFile" size="60" accept="image/jpeg,image/pjpeg"></s:file>
				<br>
				<span class="title-width-13">点击目的网址：</span>
				<s:textfield name="activityPage.mainVisualImageTargetUrl" id="mainVisualImageTargetUrlOfUploadImage" maxLength="200" size="70" />
				<br>
				<c:if test="${previewImageURL != null}">
					<span class="title-width-13">图档预览：</span>
					<img src="${imgDomain}${previewImageURL}" border="0"><input type="hidden" id="previewImage" value="Y">
				</c:if>
			</li>
			<li>
				<s:radio name="activityPage.mainVisualContentType" list="#{'3':''}" cssClass="ipt-radio htmlFile"></s:radio>
				<span class="title-width-13">html档位置：</span>
				<s:textfield name="activityPage.mainVisualHtmlFilePath" id="mainVisualHtmlFilePath" maxLength="200" size="70" />
			</li>
			<li>
				<s:radio name="activityPage.mainVisualContentType" list="#{'4':''}" cssClass="ipt-radio htmlCode"></s:radio>
				<span class="title-width-13">自定html代码：</span>
				<br> &nbsp;
				<s:textarea name="activityPage.mainVisualHtmlContent" id="mainVisualHtmlContent" cols="80" rows="5" />
			</li>
		</ul>
		<s:hidden name="activityPage.id" />
		</s:form>
		<a name="blockDetail" />
		<c:if test="${activityPage.id != null}">
			<!-- 活動商品區塊 -->
			<s:action name="block/listBlock" executeResult="true">
				<s:param name="pageId" value="activityPage.id" />
			</s:action>
		</c:if>
		
		<p class="f-link">
			<a href="#" id="saveButton">储存</a>
			<a href="search.do">回活动页面列表</a>
		</p>
		
    </div>






